﻿HAM ABS

Dim MyNumber 
MyNumber = Abs(50.3) 
MyNumber = Abs(-50.3) 

HAM ARRAY

Dim MyWeek, MyDay
    MyWeek = Array("Mon", "Tue", "Wed", _
"Thu", "Fri", "Sat", "Sun")
MyDay = MyWeek(2)
 MyDay = MyWeek(4)

HAM ASC

Dim MyNumber 
MyNumber = Asc("A") 
MyNumber = Asc("a") 
MyNumber = Asc("Apple") 

HAM ATN

Dim pi
pi = 4 * Atn(1)
MsgBox pi

HAM CALLBYNAME

Private Sub Command1_Click()
    CallByName Text1, "MousePointer", VbLet, _
vbCrosshair
    Result = CallByName(Text1, "MousePointer", _
VbGet)
    CallByName Text1, "Move", VbMethod, 100, 100
End Sub

HAM CHOOSE

Private Sub Command1_Click()
    i = GetChoice(2)
    MsgBox i
End Sub
Function GetChoice(Ind As Integer)
   GetChoice = _
Choose(Ind, "Speedy", "United", "Federal")
End Function

HAM CHR

Private Sub Command1_Click()
Dim MyChar
MyChar = Chr(65)
MyChar = Chr(97)
MyChar = Chr(62)
MyChar = Chr(37)
End Sub

HAM COS

Private Sub Command1_Click()
    Dim MyAngle, MySecant
    MyAngle = 1.3
MySecant = 1 / Cos(MyAngle)
MsgBox MySecant
End Sub

HAM CREATEOBJECT

Private Sub Command1_Click()
    Dim Conn, Rst
    Dim strData As String, strCon As String
Set Conn = CreateObject("ADODB.Connection")
Set Rst = CreateObject("ADODB.Recordset")
    strCon= "Provider=Microsoft.Jet.OLEDB.3.51;"
    strCon=strConn &"Persist Security Info=False;"
    strCon=strConn&"Data Source=C:\Northwind.mdb"
Conn.Open strCon
    Rst.CursorLocation = 3
Rst.Open "Select * from Customers", Conn, 0, 3
    If Rst.RecordCount > 0 Then
        Rst.MoveFirst
        Do Until Rst.EOF
            strData = strData & Rst("CompanyName")
            Rst.MoveNext
        Loop
    End If
Rst.Close
Conn.Close
Set Rst = Nothing
Set Conn = Nothing
End Sub

HAM CURDIR

Private Sub Command1_Click()
    Dim strPath As String
    strPath = CurDir()
    MsgBox strPath
End Sub
Private Sub Command1_Click()
    Dim strPath As String
    strPath = App.Path()
    MsgBox strPath
End Sub

HAM DATE

Private Sub Command1_Click()
    MsgBox Date$
    MsgBox Date
End Sub

HAM DATEADD

Private Sub Command1_Click()
    Dim FirstDate As Date
Dim IntervalType As String
    Dim Number As Integer
    Dim Msg As String
    IntervalType = "m"
FirstDate = Date
    Number= _
InputBox("Enter number of months to add")
    Msg = "New date: " & DateAdd(IntervalType, _
Number, FirstDate)
MsgBox Msg

IntervalType = "d"
    Number = InputBox("Enter number of day to add")
    Msg = "New date: " & DateAdd(IntervalType, _
Number, FirstDate)
MsgBox Msg
End Sub

HAM DATEDIFF

Dim TheDate As Date   
Dim Msg
TheDate = InputBox("Enter a date")
Msg = "Days from today: " & _
DateDiff("d", Now, TheDate)
MsgBox Msg

HAM DATEPART

Dim TheDate As Date   
Dim Msg
TheDate = InputBox("Enter a date")
Msg = "Quarter: " & DatePart("q", TheDate)
MsgBox Msg

HAM DATESERIAL

Private Sub Command1_Click()
    Dim MyDate
MyDate = DateSerial(1969, 2, 12)
    MsgBox MyDate
MyDate = DateSerial(1969, 35, 12)
    MsgBox MyDate
MyDate = DateSerial(1990 - 10, 8 - 2, 1 - 1)
    MsgBox MyDate
End Sub

HAM DATEVALUE

Private Sub Command1_Click()
Dim MyDate
    MyDate = DateValue("February 12, 1969")
MsgBox MyDate
    MyDate = DateValue("Feb 12, 1999")
MsgBox MyDate
    MyDate = DateValue("25/12/2000")
MsgBox MyDate
    MyDate = DateValue("28-12-2003")
MsgBox MyDate
    MyDate = DateValue("28-Apr-2004") + 2
MsgBox MyDate
End Sub

HAM DAY

Private Sub Command1_Click()
    Dim MyDate, MyDay
    MyDate = #12/25/2004#
MyDay = Day(MyDate)
MsgBox MyDay
    MyDate = #12/25/2004#
MyDay = Day(MyDate)
MsgBox MyDay
End Sub

HAM DDB

Private Sub Command1_Click()
    Dim Fmt, InitCost, SalvageVal
    Dim MonthLife, LifeTime
    Dim DepYear, Depr
    Const YRMOS = 12
Fmt = "###,##0.00"
    InitCost = _
     InputBox("Nhaäp trò giaù ban ñaàu cuûa taøi saûn?")
    SalvageVal = _
     InputBox("Nhaäp trò giaù cuoái cuøng cuûa taøi saûn.")
    MonthLife = _
     InputBox("Nhaäp trò giaù thaùng söû duïng?")
    Do While MonthLife < YRMOS
MsgBox " THôøi gian cuûa taøi saûn phaûi treân 1 naêm."
        MonthLife = _
InputBox("Nhaäp trò giaù thaùng söû duïng?")
    Loop
    LifeTime = MonthLife / YRMOS
If LifeTime <> Int(MonthLife / YRMOS) Then
        LifeTime = Int(LifeTime + 1)
End If
    DepYear = _
CInt(InputBox("Nhaäp soá naêm tính khaáu hao."))
    Do While DepYear < 1 Or DepYear > LifeTime
       MsgBox "Baïn phaûi nhaäp ít nhaát 1 " & _
" naêm nhöng khoâng lôùn hôn " & LifeTime
       DepYear = _
InputBox("Nhaäp soá naêm tính khaáu hao.")
    Loop
Depr = DDB(InitCost, SalvageVal, _
LifeTime, DepYear)
    MsgBox "Khaáu hao laø " & _
    DepYear & " is " & Format(Depr, Fmt) & "."
End Sub

HAM DIR

Private Sub Command1_Click()
   Dim MyFile, MyPath, MyName
MyPath = "c:\"   
      If MyName <> "." And MyName <> ".." Then
If (GetAttr(MyPath & MyName) And 
vbDirectory) = vbDirectory Then
              Debug.Print MyName   
End If   
       End If
       MyName = Dir   
Loop
End Sub

HAM DOEVENTS

Private Sub Command1_Click()
    Form2.Show
    Dim I, OpenForms
For I = 1 To 150000
If I Mod 1000 = 0 Then
          
            OpenForms = DoEvents
        End If
    Next I

    MsgBox OpenForms
End Sub

HAM ENVIRON

Private Sub Command1_Click()
    Dim EnvString, Indx, Msg, PathLen

    Indx = 1

    Do
       EnvString = Environ(Indx)

       If Left(EnvString, 5) = "PATH=" Then

            PathLen = Len(Environ("PATH"))
Msg = "PATH entry = " & Indx & _
            " and length = " & PathLen
            Exit Do
        Else
          Indx = Indx + 1

        End If
   Loop Until EnvString = ""
    If PathLen > 0 Then
       MsgBox Msg

    Else
       MsgBox "No PATH environment variable exists."
    End If
End Sub

HAM EOF

Private Sub Command1_Click()
    Dim InputData
Open "C:\arrays.cs" For Input As #1

    Do While Not EOF(1)

        Line Input #1, InputData

        Debug.Print InputData
    Loop

    Close #1
End Sub

HAM ERROR

Private Sub Command1_Click()
    On Error Goto myErr
    Dim InputData

    Open "C:\arrays.cs" For Input As #1

    Do While Not EOF(1)

        Line Input #1, InputData

        Debug.Print InputData
    Loop

    Close #1
    Exit Sub
myErr:

      Debug.Print Error(Err.Number)

End Sub

HAM EXP

Private Sub Command1_Click()
    Dim MyAngle, MyHSin

    MyAngle = 1.3

    MyHSin = (Exp(MyAngle) - Exp(-1 * MyAngle)) / 2
    MsgBox MyHSin
End Sub

HAM FILEATTR

Private Sub Command1_Click()
On Error Resume Next
Dim FileNum, Mode, Handle
    FileNum = 1

     Open "C:\arrays.cs" For Append As FileNum

     Mode = FileAttr(FileNum, 1)

     Handle = FileAttr(FileNum, 2)

     Close FileNum

     MsgBox Handle
     MsgBox Mode
End Sub

HAM FILEDATETIME

Private Sub Command1_Click()
    On Error Resume Next
    Dim MyStamp

    MyStamp = FileDateTime("C:\AUTOEXEC.BAT")

    MsgBox MyStamp
End Sub

HAM FILELEN
Private Sub Command1_Click()
    On Error Resume Next
    Dim MySize
    MySize = FileLen("C:\logo_RCV.gif")

    MsgBox MySize
End Sub

HAM FORMAT

Private Sub Command1_Click()
    On Error Resume Next
    Dim MyTime, MyDate, MyStr
    MyTime = #5:04:23 PM#
    MyDate = #1/27/1993#

    MyStr = Format(Time, "Long Time")
    MsgBox MyStr

    MyStr = Format(Date, "Long Date")
    MsgBox MyStr
    MyStr = Format(MyTime, "h:m:s")

    MsgBox MyStr
    MyStr = Format(MyTime, "hh:mm:ss AMPM")

    MsgBox MyStr
    MyStr = Format(MyDate, "dddd, mmm d yyyy")

    MsgBox MyStr

    MyStr = Format(23)

    MsgBox MyStr
    
    MyStr = Format(5459.4, "##,##0.00")

    MsgBox MyStr
    MyStr = Format(334.9, "###0.00")
        MsgBox MyStr
    MyStr = Format(5, "0.00%")

    MsgBox MyStr
    MyStr = Format("HELLO", "<")

    MsgBox MyStr
    MyStr = Format("This is it", ">")

    MsgBox MyStr
End Sub

HAM FORMATCURRENCY

Private Sub Command1_Click()
    On Error Resume Next
    Dim cr, st

    cr = 100000.23

    st = FormatCurrency(cr, 2, vbTrue)

    MsgBox st
    cr = 0.23
    st = FormatCurrency(cr, 2, vbFalse)

    MsgBox st
    st = FormatCurrency(cr, 2, vbTrue)

    MsgBox st
    cr = -100000.23
    st = FormatCurrency(cr, 2, vbTrue, vbTrue)

    MsgBox st
    st = FormatCurrency(cr, 2, vbTrue, vbFalse)

    MsgBox st
    st = _
      FormatCurrency(cr,2,vbTrue,vbFalse,vbTrue)

    MsgBox st
    st = _
      FormatCurrency(cr,2,vbTrue,vbFalse,vbFalse)

    MsgBox st
End Sub

HAM FORMATDATETIME

Private Sub Command1_Click()
    On Error Resume Next
    Dim dstr, st
    dstr = Date
    st = FormatDateTime(dstr, vbGeneralDate)

    MsgBox st
    st = FormatDateTime(dstr, vbLongDate)

    MsgBox st
    st = FormatDateTime(dstr, vbLongTime)

    MsgBox st
    st = FormatDateTime(dstr, vbShortDate)

    MsgBox st
    st = FormatDateTime(dstr, vbShortTime)

    MsgBox st
End Sub

HAM FORMATNUMBER


Private Sub Command1_Click()
    On Error Resume Next
     Dim cr, st
cr = 100000.23

       st = FormatNumber(cr, 2, vbTrue)

       MsgBox st
       cr = 0.23
       st = FormatNumber(cr, 2, vbFalse)

       MsgBox st
       st = FormatNumber(cr, 2, vbTrue)

       MsgBox st
       cr = -100000.23
       st = FormatNumber(cr, 2, vbTrue, vbTrue)

       MsgBox st
        st = FormatNumber(cr, 2, vbTrue, vbFalse)

       MsgBox st
       st = _
        FormatNumber(cr, 2, vbTrue, vbFalse, vbTrue)

       MsgBox st
       st = _
       FormatNumber(cr, 2, vbTrue, vbFalse, vbFalse)

       MsgBox st
End Sub

HAM FORMATPERCENT


Private Sub Command1_Click()
    On Error Resume Next
     Dim cr, st

       cr = 0.215

       st = FormatPercent (cr, 2, vbTrue)

       MsgBox st
       cr = 0.035
       st = FormatPercent (cr, 2, vbFalse)

       MsgBox st
       st = FormatPercent (cr, 2, vbTrue)

       MsgBox st
       cr = -0.3
       st = FormatNumber(cr, 2, vbTrue, vbTrue)

       MsgBox st
        st = FormatPercent (cr, 2, vbTrue, vbFalse)

       MsgBox st
       st = FormatPercent (cr, 2, _
vbTrue, vbFalse, vbTrue)

       MsgBox st
       st = FormatPercent (cr, 2, _
vbTrue, vbFalse, vbFalse)

       MsgBox st
End Sub

HAM FREEFILE

Private Sub Command1_Click()
    On Error Resume Next
    Dim MyIndex, FileNumber
    For MyIndex = 1 To 5

        FileNumber = FreeFile

        Open "TEST" & _
MyIndex For Output As #FileNumber

        Write #FileNumber, "This is a sample."

        Close #FileNumber

    Next MyIndex
End Sub

HAM FV
Private Sub Command1_Click()
    On Error Resume Next
    Dim Fmt, Payment, APR, TotPmts
    Dim PayType, PVal, FVal

    Const ENDPERIOD = 0, BEGINPERIOD = 1

    Fmt = "###,###,##0.00"

    Payment = InputBox("Moãi thaùng göûi bao nhieâu ?”) 

    APR = InputBox("Laõi suaát tieàn göûi.")
    If APR > 1 Then APR = APR / 100

    TotPmts = InputBox("Soá thaùng göûi")

    PayType = MsgBox("Göû tieàn vaøo cuoái thaùng?", _
 vbYesNo)
    If PayType = vbNo Then
        PayType = BEGINPERIOD
    Else
        PayType = ENDPERIOD
    End If

    PVal = InputBox("Soá tieàn hieän haønh")

    FVal = FV(APR / 12, TotPmts, -Payment, -PVal, _
PayType)
    MsgBox "Tieàn seõ nhaän ñöôïc trong töông lai " & _
Format(FVal, Fmt) & "."
End Sub

HAM GETALLSETTINGS

Private Sub Command1_Click()
    On Error Resume Next


    Dim MySet As Variant
    Dim intSettings As Integer

    SaveSetting appname:="MyApp", _
section:="Startup", _
Key:="Top", setting:=75

    SaveSetting "MyApp", "Startup", "Left", 50

    MySet = GetAllSettings( _
        appname:="MyApp", section:="Startup")

    For intSettings = _
       LBound(MySet, 1) To UBound(MySet, 1)
          Debug.Print MySet (intSettings, 0), _
          MySettings(intSettings, 1)
    Next intSettings

    DeleteSetting "MyApp", "Startup"
End Sub

HAM GETATTR


Private Sub Command1_Click()
    On Error Resume Next
    Dim MyAttr

    MyAttr = GetAttr("TESTFILE")

    Debug.Print MyAttr And vbHidden
    

    MyAttr = GetAttr("TESTFILE")
 
     Debug.Print MyAttr And (vbHidden + vbReadOnly)
    

    MyAttr = GetAttr("MYDIR")

    Debug.Print MyAttr
End Sub

HAM GETAUTOSERVERSETTINGS

Private Sub Command1_Click()
    On Error Resume Next

    Dim oRegClass As New RegClass
    Dim vRC As Variant
    vRC = oRegClass.GetAutoServerSettings _
    ("HelloProj.HelloClass")
    If Not (IsEmpty(vRC)) Then
        If vRC(1) Then
           MsgBox "Hello is registered remotely on a " _
           & "server named: " & vRC(1)
        Else
           MsgBox "Hello is registered locally."
        End If
    End If
End Sub

HAM GETSETTING


Private Sub Command1_Click()
    On Error Resume Next

    SaveSetting appname:="MyApp", _
section:="Startup", _
Key:="Top", setting:=75

    SaveSetting "MyApp", "Startup", "Left", 50

    Debug.Print GetSetting(appname := "MyApp", _
section := "Startup", _ key := "Left", _
default := "25") 

    DeleteSetting "MyApp", "Startup"
End Sub

HAM HEX


Private Sub Command1_Click()
    On Error Resume Next
    Dim MyHex
    MyHex = Hex(5)

    MyHex = Hex(10)

    MyHex = Hex(459)

End Sub

HAM HOUR


Private Sub Command1_Click()
    On Error Resume Next
    Dim MyTime, MyHour
    MyTime = #4:35:17 PM#

    MyHour = Hour(MyTime)

End Sub

HAM IIF

Private Sub Command1_Click()
        result = CheckIt(5000)
End Function
Function CheckIt(TestMe As Integer)
   CheckIt = IIf(TestMe > 1000, "Large", "Small")
End Function

HAM INPUT


Private Sub Command1_Click()
    Dim MyChar

    Open "TESTFILE" For Input As #1

    Do While Not EOF(1)

        MyChar = Input(1, #1)

        Debug.Print MyChar
    Loop

    Close #1
End Function

HAM INPUTBOX


Private Sub Command1_Click()
    Dim Message, Title, Default, MyValue

    Message = "Enter a value between 1 and 3"
    
    Title = "InputBox Demo"
   
    Default = "1"
  
    MyValue = InputBox(Message, Title, Default)
    

    MyValue = InputBox(Message, Title, , , , _
"DEMO.HLP", 10)
    

    MyValue = InputBox(Message, Title, Default, 100, 100)
End Sub

HAM INSTR


Private Sub Command1_Click()
    Dim SearchString, SearchChar, MyPos

    SearchString = "http://www.huukhang.com"

    SearchChar = "h"

    MyPos = InStr(13, SearchString, SearchChar, 1)

    MyPos = InStr(2, SearchString, SearchChar, 0)
    

    MyPos = InStr(SearchString, SearchChar)

    MyPos = InStr(1, SearchString, "W")

End Sub

HAM INSTRREV


Private Sub Command1_Click()
    Dim StrCheck, StrMatch, MyPos

    StrCheck = "phamhuukhang"

    StrMatch = "h"
    MyPos = InStrRev(StrCheck, StrMatch, 4, 1)

    MsgBox MyPos
    MyPos = InStrRev(StrCheck, StrMatch, 6, 1)

    MsgBox MyPos
    MyPos = InStrRev(StrCheck, StrMatch, 10, 1)

    MsgBox MyPos
End Sub

HAM INT VAØ FIX

Private Sub Command1_Click()
    Dim MyNumber
    MyNumber = Int(99.8)

    MyNumber = Fix(99.2)

    
    MyNumber = Int(-99.8)

    MyNumber = Fix(-99.8)

    MyNumber = Int(-99.2)

    MyNumber = Fix(-99.2)

End Sub


HAM IPMT

Private Sub Command1_Click()
    On Error Resume Next
    Dim FVal, Fmt, PVal, APR, TotPmts, PayType
    Dim Period, IntPmt, TotInt, Msg
    Const ENDPERIOD = 0, BEGINPERIOD = 1

    FVal = 0

    Fmt = "###,###,##0.00"

    PVal = InputBox( _
"Soá tieàn baïn vay?")
    APR = _
InputBox("Tyû giaù töøng kyø traû?")
    If APR > 1 Then APR = APR / 100

    TotPmts = InputBox("Soá thaùng caàn traû?")
    PayType = MsgBox("Baïn muoán traû cuoái thaùng?", _
vbYesNo)
    If PayType = vbNo Then 
PayType = BEGINPERIOD 
    Else 
PayType = ENDPERIOD
    End If
    For Period = 1 To TotPmts

       IntPmt = IPmt(APR / 12, Period, TotPmts, _
-PVal, FVal, PayType)
       TotInt = TotInt + IntPmt
    Next Period
    Msg = _
Format(TotInt, Fmt)
    Msg = Msg & " in interest for this loan."
    MsgBox Msg

End Sub

HAM ISARRAY

Private Sub Command1_Click()
    On Error Resume Next

    Dim MyArray(1 To 5) As Integer

    Dim  YourArray, MyCheck

    YourArray = Array(1, 2, 3)

    MyCheck = IsArray(MyArray)

    MyCheck = IsArray(YourArray)

End Sub

HAM ISDATE


Private Sub Command1_Click()
    On Error Resume Next
    Dim MyDate, YourDate, NoDate, MyCheck
    MyDate = "February 12, 1969"
    YourDate = #2/12/1969#
    NoDate = "Hello"
    MyCheck = IsDate(MyDate)

    MyCheck = IsDate(YourDate)

    MyCheck = IsDate(NoDate)

End Sub

HAM ISEMPTY

Private Sub Command1_Click()
    On Error Resume Next
    Dim MyVar, MyCheck
    MyCheck = IsEmpty(MyVar)

    MyVar = Null

    MyCheck = IsEmpty(MyVar)

    MyVar = Empty

    MyCheck = IsEmpty(MyVar)

End Sub

HAM ISERROR

Private Sub Command1_Click()
    On Error Resume Next
    Dim ReturnVal, MyCheck
    UserFunction = CVErr(32767)
    ReturnVal = UserFunction
    MyCheck = IsError(ReturnVal)

End Sub

HAM ISNULL

Private Sub Command1_Click()
    On Error Resume Next
    Dim MyVar, MyCheck
    MyCheck = IsNull(MyVar)
MyVar = ""
    MyCheck = IsNull(MyVar)

    MyVar = Null
    MyCheck = IsNull(MyVar)

End Sub

HAM ISNUMERIC

Private Sub Command1_Click()
    On Error Resume Next
    Dim MyVar, MyCheck
    MyVar = "53"

    MyCheck = IsNumeric(MyVar)

    MyVar = "459.95"
MyCheck = IsNumeric(MyVar)

    MyVar = "45 Help"

    MyCheck = IsNumeric(MyVar)

End Sub

HAM ISOBJECT

Private Sub Command1_Click()
    Dim MyInt As Integer, YourObject, MyCheck

    Dim MyObject As Object
    Set YourObject = MyObject

    MyCheck = IsObject(YourObject)

    MyCheck = IsObject(MyInt)

End Sub

HAM JOIN


Private Sub Command1_Click()
    Dim MyWeek, MyDay
    MyWeek = Array("Mon","Tue","Wed","Thu", "Fri", 
      "Sat", "Sun")
    MyDay = Join(MyWeek)

    MsgBox MyDay
    MyDay = Join(MyWeek, ",")

    MsgBox MyDay
End Sub

HAM LBOUND

Private Sub Command1_Click()
    Dim MyWeek, MinElement
    MyWeek = Array("Mon", "Tue", "Wed", "Thu", _
"Fri", "Sat", "Sun")
    MinElement = LBound(MyWeek)

    MsgBox MinElement
    Dim A(1 To 100, 0 To 3, -3 To 4)
    MinElement = LBound(A)

    MsgBox MinElement
    MinElement = LBound(A, 1)

    MsgBox MinElement
    MinElement = LBound(A, 2)

    MsgBox MinElement
    MinElement = LBound(A, 3)

    MsgBox MinElement
End Sub

HAM LCASE

Private Sub Command1_Click()
    Dim UpperCase, LowerCase
    UpperCase = "Hello HuuKhang.COM"

    LowerCase = LCase(UpperCase)

    MsgBox LowerCase
End Sub

HAM LEFT

Private Sub Command1_Click()
    Dim AnyString, MyStr
    AnyString = "Hello World"

    MyStr = Left(AnyString, 1)

    MsgBox MyStr
    MyStr = Left(AnyString, 7)

    MsgBox MyStr
    MyStr = Left(AnyString, 20)

    MsgBox MyStr
End Sub

HAM LEN

Private Sub Command1_Click()
    Type CustomerRecord

       ID As Integer

       Name As String * 10

       Address As String * 30
    End Type
    
    Dim Customer As CustomerRecord

    Dim MyInt As Integer, MyCur As Currency
    Dim MyString, MyLen
    MyString = "Hello World"

    MyLen = Len(MyInt)

    MyLen = Len(Customer)

    MyLen = Len(MyString)

    MyLen = Len(MyCur)

End Sub

HAM LOADPICTURE

Private Sub Command1_Click()
    Dim Msg As String

   On Error Resume Next

   Height = 3990
   Width = 4890
Picture1.Picture = _
    LoadPicture("PAPER.CUR", vbLPCustom, _
        vbLPColor, 32, 32)

   If Err Then
      MsgBox Msg
Exit Sub

   End If

   Msg = "Choose OK to clear the bitmap from the picturebox."
   MsgBox Msg
   Picture1.Picture = LoadPicture()

End Sub

HAM LOC

Private Sub Command1_Click()
    Dim MyLocation, MyLine
    Open "TESTFILE" For Binary As #1

    Do While MyLocation < LOF(1)

       MyLine = MyLine & Input(1, #1)

       MyLocation = Loc(1)

       Debug.Print MyLine; Tab; MyLocation
    Loop
    Close #1

End Sub

HAM LOF

Private Sub Command1_Click()
   Dim FileLength
    Open "TESTFILE" For Input As #1

    FileLength = LOF(1)

    Close #1
   
End Sub

HAM LOG

Private Sub Command1_Click()
    Dim MyAngle, MyLog

    MyAngle = 1.3

    MyLog = _
Log(MyAngle + Sqr(MyAngle * MyAngle + 1))
End Sub

HAM LTRIM, RTRIM, TRIM


Private Sub Command1_Click()
    Dim MyString, TrimString
    MyString = "  <-Trim->  "

    TrimString = LTrim(MyString)

    TrimString = RTrim(MyString)

    TrimString = LTrim(RTrim(MyString))


    TrimString = Trim(MyString)

End Sub

HAM MID

Private Sub Command1_Click()
    Dim AnyString, MyStr
    AnyString = "Hello World"

    MyStr = Mid(AnyString, 7,1)

    MsgBox MyStr
    MyStr = Mid(AnyString, 7,6)

    MsgBox MyStr
    MyStr = Mid(AnyString, 7)

    MsgBox MyStr
End Sub

HAM MINUTE

Private Sub Command1_Click()
    On Error Resume Next
    Dim MyTime, MyMinute
    MyTime = #4:35:17 PM#

  MyMinute = Minute(MyTime)

End Sub

 HAM MONTH

Private Sub Command1_Click()
    Dim MyDate, MyMonth
    MyDate = #11/25/2004#
MyMonth = Month(MyDate)
MsgBox MyMonth
    MyDate = #12/25/2004#
    
  MyMonth = Month(MyDate)

    MsgBox MyMonth
End Sub

HAM MONTHNAME

Private Sub Command1_Click()
    Dim MyDate, MyMonth
    MyDate = #11/25/2004#
MyMonth = MonthName(Month(MyDate))
MsgBox MyMonth
    MyDate = #12/25/2004#
MyMonth = MonthName(Month(MyDate), True)

    MsgBox MyMonth   
End Sub

HAM MSGBOX

Private Sub Command1_Click()
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "Do you want to continue ?"

    Style = vbYesNo + vbCritical + vbDefaultButton2

    Title = "MsgBox Demonstration"

    Help = "DEMO.HLP"

    Ctxt = 1000
    Response = _
MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then

       MyString = "Yes"
    Else

       MyString = "No"
    End If
End Sub

HAM NOW

Private Sub Command1_Click()
    Dim myCurrTime
    myCurrTime = Now
    MsgBox myCurrTime
End Sub

HAM NPER

Dim FVal, PVal, APR, Payment
    Dim PayType, TotPmts
    Const ENDPERIOD = 0, BEGINPERIOD = 1
    FVal = 0   

    PVal = InputBox("Soá tieàn baïn caàn vay?")
    APR = InputBox("Tyû giaù?")
    If APR > 1 Then APR = APR / 100

    Payment = _
InputBox("Traû bao nhieâu trong moät thaùng?")
    PayType = MsgBox("Traû vaøo cuoái thaùng?", _
vbYesNo)
    If PayType = vbNo Then
        PayType = BEGINPERIOD
    Else
        PayType = ENDPERIOD
    End If

    TotPmts = _
     NPer(APR / 12, -Payment, PVal, FVal, PayType)
    If Int(TotPmts) <> TotPmts Then
        TotPmts = Int(TotPmts) + 1
    End If
    MsgBox "Baûn phaûi " & TotPmts & " thaùng."

HAM NPV

Private Sub Command1_Click()
    Dim Fmt, Guess, RetRate, NetPVal, Msg

    Static Values(5) As Double
Fmt = "###,##0.00"
RetRate = 0.0625

    Values(0) = -70000

    Values(1) = 22000
    Values(2) = 25000
    Values(3) = 28000
    Values(4) = 31000
    NetPVal = NPV(RetRate, Values())

    Msg = "NPV laø "
    Msg = Msg & Format(NetPVal, Fmt) & "."
    MsgBox Msg
End Sub

HAM OCT

Private Sub Command1_Click()
    Dim MyOct
    MyOct = Oct(4)

    MyOct = Oct(8)
MyOct = Oct(459)

End Sub

HAM PMT

Private Sub Command1_Click()
    Dim Fmt, FVal, PVal, APR, TotPmts
    Dim  PayType, Payment
    Const ENDPERIOD = 0, BEGINPERIOD = 1
    Fmt = "###,###,##0.00"
    FVal = 0
    PVal = InputBox("Soá tieàn vay?")
    APR = InputBox("Laõi suaát?")
    If APR > 1 Then APR = APR / 100
TotPmts = InputBox("Traû bao nhieâu thaùng?")
    PayType = MsgBox("Traû vaøo cuoái thaùng", vbYesNo)
    If PayType = vbNo Then
        PayType = BEGINPERIOD
    Else
        PayType = ENDPERIOD
    End If
    Payment = Pmt(APR / 12, TotPmts, -PVal, _
FVal, PayType)
    MsgBox "Baïn phaûi traû " & _
Format(Payment, Fmt) & " cho moãi thaùng."
End Sub

HAM PPMT

Private Sub Command1_Click()
    Dim NL, TB, Fmt, FVal, PVal, APR
    Dim TotPmts, PayType, Payment
    Dim Msg, MakeChart, Period, P, I
    Const ENDPERIOD = 0, BEGINPERIOD = 1

    NL = Chr(13) & Chr(10)

    TB = Chr(9)

    Fmt = "###,###,##0.00"
    FVal = 0
    PVal = InputBox("Soá tieàn vay?")
    APR = InputBox("Laõi suaát?")
    If APR > 1 Then APR = APR / 100
    TotPmts = InputBox("Traû bao nhieâu thaùng?")
    PayType = MsgBox("Traû vaøo cuoái thaùng?", _
vbYesNo)
    If PayType = vbNo Then
        PayType = BEGINPERIOD
    Else
        PayType = ENDPERIOD
    End If
    Payment = Abs(-Pmt(APR / 12, TotPmts, PVal, _
FVal, PayType))

    Msg = "Traû haøng thaùng " & _
Format(Payment, Fmt) & ". "
    Msg = Msg & "Tính soá tieàn goác?"
    MakeChart = MsgBox(Msg, vbYesNo)
If MakeChart <> vbNo Then
       If TotPmts > 12 Then 
MsgBox "Only first year will be shown."
       Msg = "Month  Payment  Principal  Interest" & NL
       For Period = 1 To TotPmts
          If Period > 12 Then Exit For

          P = PPmt(APR / 12, Period, TotPmts, _
-PVal, FVal, PayType)
          P = (Int((P + 0.005) * 100) / 100)

          I = Payment - P
          I = (Int((I + 0.005) * 100) / 100)

          Msg = Msg & Period & TB & Format(Payment, Fmt)
          Msg = Msg & TB & Format(P, Fmt) & TB & _
Format(I, Fmt) & NL
       Next Period
       MsgBox Msg
   End If
End Sub

HAM PV

Private Sub Command1_Click()
    Dim Fmt, APR, TotPmts, YrIncome
    Dim  FVal, PayType, PVal
    Const ENDPERIOD = 0, BEGINPERIOD = 1
    Fmt = "###,##0.00"
    APR = 0.1

    TotPmts = 12

    YrIncome = 50000

    FVal = 1000000

    PayType = BEGINPERIOD

    PVal = PV(APR, TotPmts, -YrIncome, _
FVal, PayType)
    MsgBox "Giaù trò töông lai laø " & _
Format(PVal, Fmt) & "."
End Sub

HAM QBCOLOR


Sub ChangeBackColor(ColorCode As Integer, MyForm As Form)
   MyForm.BackColor = QBColor(ColorCode)
End Sub

HAM RATE

Private Sub Command1_Click()
    Dim Fmt, FVal, Guess, PVal
    Dim Payment, TotPmts, PayType, APR
    Const ENDPERIOD = 0, BEGINPERIOD = 1

    FVal = 0
    Guess = 0.1
    PVal = InputBox("Baïn vay bao nhieâu?")
    Payment = InputBox("Traû bao nhieâu thaùng?")
    TotPmts = InputBox("Moi thang tra bao nhieu?")
    PayType = MsgBox("Traû vaøo cuoái thaùng?", _ 
    vbYesNo)
    If PayType = vbNo Then
        PayType = BEGINPERIOD
    Else
        PayType = ENDPERIOD
    End If
    APR = (Rate(TotPmts, -Payment, PVal, _
    FVal, PayType, Guess) * 12) * 100
    MsgBox "Laõi suaát laø " & _
    Format(CInt(APR), Fmt) & " percent."
End Sub

HAM REPLACE

Private Sub Command1_Click()
    Dim strSQL As String
    strSQL = "Insert into Shippers"
End Sub

HAM RGB

Private Sub Command1_Click()
    Dim RED, I, RGBValue, MyObject
    RED = RGB(255, 0, 0)

    I = 75

    RGBValue = RGB(I, 64 + I, 128 + I)

    MyObject.Color = RGB(255, 0, 0)

End Sub

HAM RIGHT

Private Sub Command1_Click()
    Dim AnyString, MyStr
    AnyString = "Hello World"

    MyStr = Right(AnyString, 1)

    MsgBox MyStr
    MyStr = Right(AnyString, 7)
MsgBox MyStr
    MyStr = Right(AnyString, 20)

    MsgBox MyStr
End Sub

HAM RND

Private Sub Command1_Click()
    For I = 1 To 100
       Randomize (I)
       Debug.Print Rnd(I)
    Next I
End Sub

HAM ROUND

Private Sub Command1_Click()
    Dim Amount
    Amount = 15.1464
    MsgBox Round(Amount, 3)

    MsgBox Round(Amount, 2)

End Sub

HAM SECOND

Private Sub Command1_Click()
    On Error Resume Next
    Dim MyTime, MyMinute
    MyTime = #4:35:17 PM#
MyMinute = Second(MyTime)
End Sub

HAM SEEK

Private Sub Command1_Click()
    Dim MyChar
    Open "D:\Csharp\arrays.cs" For Input As #1

    Do While Not EOF(1)

       MyChar = Input(1, #1)

       Debug.Print Seek(1)

    Loop
    Close #1   
End Sub

HAM SGN

Private Sub Command1_Click()
    Dim MyVar1, MyVar2, MyVar3, MySign
    MyVar1 = 12: MyVar2 = -2.4: MyVar3 = 0
    MySign = Sgn(MyVar1)

    MySign = Sgn(MyVar2)

    MySign = Sgn(MyVar3)

End Sub

HAM SHELL

Private Sub Command1_Click()

    Dim RetVal
    RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)

End Sub

HAM SIN

Private Sub Command1_Click()
    Dim MyAngle, MySecant
    MyAngle = 1.3

    MySecant = 1 / Sin(MyAngle)

    MsgBox MySecant
End Sub

 HAM SLN

Private Sub Command1_Click()
    Dim Fmt, InitCost, SalvageVal
    Dim MonthLife, LifeTime, PDepr
    Const YEARMONTHS = 12

    Fmt = "###,##0.00"

    InitCost=InputBox("Giaù trò ban ñaàu cuûa TS?")
    SalvageVal=InputBox("Giaù trò coøn laïi cuûa TS?")
    MonthLife = InputBox("Soá thaùng tính khaáu hao?")
    Do While MonthLife < YEARMONTHS

       MsgBox "Soá thaùng lôùn hôn vaø baèng 1 naêm."
       MonthLife= _
InputBox("Soá thaùng tính khaàu hao?")
    Loop
    LifeTime = MonthLife / YEARMONTHS

    If LifeTime <> Int(MonthLife / YEARMONTHS) Then
       LifeTime = Int(LifeTime + 1)

    End If
    PDepr = SLN(InitCost, SalvageVal, LifeTime)
    MsgBox "Giaù trò khaáu hao laø " & _
    Format(PDepr, Fmt) & " per year."
End Sub

HAM SPACE

Private Sub Command1_Click()
    Dim MyString

    MyString = Space(10)

    MyString = "Hello" & Space(10) & "World"
End Sub

HAM SPLIT

Private Sub Command1_Click()
    Dim myString As String
    Dim MyArr() As String
    Dim MyArrs() As String
    Dim i As Integer
myString = "Welcome to Saigon"

    MyArr = Split(myString)

    For i = 0 To UBound(MyArr)
        Debug.Print MyArr(i)
    Next

    myString = "Xin,chao,cac,ban"
    MyArrs = Split(myString, ",", 1)
    For i = 0 To UBound(MyArrs)
        Debug.Print MyArrs(i)
    Next
End Sub

HAM SQR

Private Sub Command1_Click()
    Dim MySqr
    MySqr = Sqr(4)

    MySqr = Sqr(23)

    MySqr = Sqr(0)

    MySqr = Sqr(-4)

End Sub

HAM STR

Private Sub Command1_Click()
     Dim MyString
     MyString = Str(459)
MyString = Str(-459.65)
MyString = Str(459.001)
End Sub

HAM STRCONV


Private Sub Command1_Click()
    Dim i As Long
    Dim x() As Byte
    x = StrConv("ABCDEFG", vbFromUnicode)

    For i = 0 To UBound(x)
       Debug.Print x(i)
    Next
End Sub

HAM STRING

Private Sub Command1_Click()
    Dim MyString As String
    MyString = String(5, "*")
    Debug.Print MyString

    MyString = String(5, 42)
    Debug.Print MyString

    MyString = String(10, "ABC")
    Debug.Print MyString

End Sub


Private Sub Command1_Click()
    Dim MyString As String
    MyString = "ABC"
    MyString = StrReverse(MyString)
    Debug.Print MyString

End Sub

HAM SYD


Private Sub Command1_Click()
    Dim Fmt, InitCost, SalvageVal
    Dim MonthLife, LifeTime, DepYear, PDepr
    Const YEARMONTHS = 12

    Fmt = "###,##0.00"

    InitCost= _
InputBox("Giaù trò ban ñaàu cuûa taøi saûn?")
    SalvageVal = _
InputBox (Giaù trò coøn laïi cuûa taøi saûn sau khi 
keát thuùc thôøi kyø khaáu hao?")
    MonthLife = InputBox("Soá thaùng tính khaáu hao?")
    Do While MonthLife < YEARMONTHS

       MsgBox "Ñôøi soáng cuûa taøi saûn laø 1 naêm hay lôùn 
hôn."
       MonthLife = _
InputBox("Soá thaùng tính khaáu hao?")
    Loop
    LifeTime = MonthLife / YEARMONTHS

    If LifeTime <> Int(MonthLife / YEARMONTHS) Then
       LifeTime = Int(LifeTime + 1)
   End If
    DepYear = _
 CInt(InputBox("Giaù trò khaáu hao cuûa naêm?"))
    Do While DepYear < 1 Or DepYear > LifeTime
  MsgBox “Ñôøi soáng cuûa taøi saûn laø 1 naêm hay lôùn 
hôn " & LifeTime
        DepYear = _
CInt(InputBox("Giaù trò khaáu hao cuûa naêm?"))
    Loop
    PDepr = _
     SYD(InitCost, SalvageVal, LifeTime, DepYear)
    MsgBox "Khaáu hao naêm " & DepYear & " laø " & _
Format(PDepr, Fmt) & "."
End Sub

HAM TAB

Private Sub Command1_Click()

    Open "C:\TESTFILE.txt" For Output As #1

    Print #1, "Hello"; Tab(20); "World."

    Print #1, "Hello"; Tab; "World"
    Close #1

End Sub

HAM TAN

Private Sub Command1_Click()
    Dim MyAngle, MyCotangent
    MyAngle = 1.3
MyCotangent = 1 / Tan(MyAngle)

End Sub

HAM TIME

Private Sub Command1_Click()
    Dim MyTime
    MyTime = Time
     
End Sub

HAM TIMESERIAL

Private Sub Command1_Click()
    Dim MyTime
    MyTime = TimeSerial(16, 35, 17)
    Debug.Print MyTime

    MyTime = TimeSerial(19, -35, -17)
    Debug.Print MyTime

End Sub

HAM TIMEVALUE

Private Sub Command1_Click()
    Dim MyTime
    MyTime = TimeValue("4:35:17 PM")
    Debug.Print MyTime

    MyTime = TimeValue("4:35:17 AM")
    Debug.Print MyTime

End Sub

HAM TYPENAME

Private Sub Command1_Click()

    Dim NullVar, MyType, StrVar As String
    Dim IntVar As Integer, CurVar As Currency
    Dim ArrayVar(1 To 5) As Integer
    NullVar = Null

    MyType = TypeName(StrVar)

    MyType = TypeName(IntVar)

    MyType = TypeName(CurVar)

    MyType = TypeName(NullVar)

    MyType = TypeName(ArrayVar)

End Sub

HAM UBOUND

Private Sub Command1_Click()
    Dim Upper
    Dim MyArray(1 To 10, 5 To 15, 10 To 20)

    Dim AnyArray(10)
    Upper = UBound(MyArray, 1)

    Upper = UBound(MyArray, 3)

    Upper = UBound(AnyArray)

End Sub

HAM UCASE


Private Sub Command1_Click()
    Dim Upper
    Dim MyString As String

MyString =”Hello World”
     Upper = UCase(MyString)

End Sub

HAM VAL


Private Sub Command1_Click()
    Dim MyValue
    MyValue = Val("2457")+1
    Debug.Print MyValue

    MyValue = Val(" 2 45 7")
    Debug.Print MyValue

    MyValue = Val("24 and 57")
    Debug.Print MyValue

    MyValue = Val("A 24 and 57")
    Debug.Print MyValue

    MyValue = Val("")
    Debug.Print MyValue

End Sub

HAM WEEKDAY

Private Sub Command1_Click()
    Dim MyDate, MyWeekDay
    MyDate = #2/12/1969#

    MyWeekDay = Weekday(MyDate)
    Debug.Print MyWeekDay

    MyWeekDay = Weekday(Date)
    Debug.Print MyWeekDay    
End Sub

HAM WEEKDAYNAME

Private Sub Command1_Click()
    Dim MyDate, MyWeekDay
    MyWeekDay = 4
MyDate = WeekdayName(MyWeekDay)
    Debug.Print MyDate
MyDate = WeekdayName(6, True)
    Debug.Print MyDate
End Sub

HAM YEAR


Private Sub Command1_Click()
    Dim MyDate, MyYear
    MyDate = #2/12/2003#
MyYear = Year(MyDate)
    Debug.Print MyDate
End Sub

























